#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bird.h"

static void SetBirdName(struct Bird *Bird, char *Name)
{
    if(Bird == NULL){
        return;
    }
    Bird->Name = Name;
}

static void SetBirdAddr(struct Bird *Bird, char *Addr)
{
    if(Bird == NULL){
        return;
    }
    Bird->Addr = Addr;
}

static void SetBirdColor(struct Bird *Bird, const int Color)
{
    if(Bird == NULL){
        return;
    }
    Bird->Color = Color;
}

static void SetBirdWeight(struct Bird *Bird, const int Weight)
{
    if(Bird == NULL){
        return;
    }
    Bird->Weight = Weight;
}

static char *GetName(struct Bird *Bird)
{
    if(Bird == NULL){
        return NULL;
    }
    
    return Bird->Name;
}

static int GetColor(struct Bird *Bird)
{
    if(Bird == NULL){
        return INVALID_COLOR;
    }

    return Bird->Color;
}

static void LayEggs(struct Bird *Bird)
{
    if(Bird == NULL){
        return;
    }

    printf("bird lay eggs\n");
}

void BirdInit(struct Bird *Bird)
{
    if(Bird == NULL){
        return;
    }
    Bird->SetAddr = SetBirdAddr;
    Bird->SetColor = SetBirdColor;
    Bird->SetName = SetBirdName;
    Bird->SetWeight = SetBirdWeight;

    Bird->GetColor = GetColor;
    Bird->GetName = GetName;

    Bird->LayEggs = LayEggs;

    Bird->SetAddr(Bird, "Guangzhou");
    Bird->SetColor(Bird, RED);
    Bird->SetWeight(Bird, 10);
    Bird->SetName(Bird, "Xiaoming");
}

void BirdDeinit(struct Bird *Bird)
{
    if(Bird == NULL){
        return;
    }

    memset(Bird, 0, sizeof(struct Bird));
}